package com.ruoyi.project.dict.jieshi.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.dict.jieshi.domain.CiJieshi;
import com.ruoyi.project.dict.jieshi.service.ICiJieshiService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 词语解释(用户)Controller
 *
 * @author shixiangwen
 * @date 2020-10-20
 */
@Controller
@RequestMapping("/dict/jieshi")
public class CiJieshiController extends BaseController {

    private String prefix = "dict/jieshi";

    @Autowired
    private ICiJieshiService ciJieshiService;

    @RequiresPermissions("dict:jieshi:view")
    @GetMapping()
    public String jieshi() {
        return prefix + "/jieshi";
    }

    /**
     * 查询词语解释(用户)列表
     */
    @RequiresPermissions("dict:jieshi:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CiJieshi ciJieshi) {
        startPage();
        List<CiJieshi> list = ciJieshiService.selectCiJieshiList(ciJieshi);
        return getDataTable(list);
    }

    /**
     * 导出词语解释(用户)列表
     */
    @RequiresPermissions("dict:jieshi:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CiJieshi ciJieshi) {
        List<CiJieshi> list = ciJieshiService.selectCiJieshiList(ciJieshi);
        ExcelUtil<CiJieshi> util = new ExcelUtil<CiJieshi>(CiJieshi.class);
        return util.exportExcel(list, "jieshi");
    }

    /**
     * 新增词语解释(用户)
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存词语解释(用户)
     */
    @RequiresPermissions("dict:jieshi:add")
    @Log(title = "词语解释(用户)", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CiJieshi ciJieshi) {
        return toAjax(ciJieshiService.insertCiJieshi(ciJieshi));
    }

    /**
     * 修改词语解释(用户)
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        CiJieshi ciJieshi = ciJieshiService.selectCiJieshiById(id);
        mmap.put("ciJieshi", ciJieshi);
        return prefix + "/edit";
    }

    /**
     * 修改保存词语解释(用户)
     */
    @RequiresPermissions("dict:jieshi:edit")
    @Log(title = "词语解释(用户)", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CiJieshi ciJieshi) {
        return toAjax(ciJieshiService.updateCiJieshi(ciJieshi));
    }

    /**
     * 删除词语解释(用户)
     */
    @RequiresPermissions("dict:jieshi:remove")
    @Log(title = "词语解释(用户)", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(ciJieshiService.deleteCiJieshiByIds(ids));
    }
}
